home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / reader_requests / wild / support / pytree.s < prev    next >
Text File  |  2000-02-23  |  1KB  |  51 lines

  1. ; PyTree macro: calcs the sqr of a number, using a scalable table.
  2. ; WARNING: NEGATIVE NUMBERS GIVE ABSURDE RESULTS! NO INTERNAL CHECK!
  3.  
  4. PyTree    MACRO    ;\1=x \2=Ax pointing to table \3=x^.5(result) \4=skratch
  5.     bra.b    cyc\@
  6. jump\@    move.l    (\2),\3
  7.     ble.b    fnd\@
  8.     lea.l    (\2,\3.l),\2
  9. cyc\@    move.l    (\2)+,\4
  10.     cmp.l    \4,\1
  11.     beq.b    exact\@
  12.     bgt.b    jump\@
  13.     tst.l    (\2)
  14.     bmi.b    fnd\@
  15.     addq.l    #8,\2
  16.     bra.b    cyc\@
  17. exact\@    move.l    4(\2),\3
  18.     bra.b    had\@
  19. fnd\@    addq.l    #4,\2
  20.     move.l    (\2)+,\3
  21.     cmp.l    \1,\4
  22.     beq.b    had\@
  23.     blt.b    low\@
  24. high\@    subq.l    #2,\3
  25.     sub.l    \3,\4
  26.     cmp.l    \1,\4
  27.     bgt.b    high\@
  28.     bra.b    had\@
  29. low\@    add.l    \3,\4
  30.     addq.l    #2,\3
  31.     cmp.l    \1,\4
  32.     ble.b    low\@
  33.     subq.l    #2,\3
  34. had\@    lsr.l    #1,\3
  35.     ENDM
  36.  
  37. ''    move.l    #896*896,d0
  38. ''    lea.l    Table,a0
  39. ''    PyTree    d0,a0,d1,d2
  40.  
  41. ; Tested with 900*900: ok,exact (goes into high cycle)
  42. ; Tested with 900*900+1: ok,same
  43. ; Tested with 895*895: ok,exact (goes into low cycle)
  44. ; Tested with 895*895+1: BAD, gives 896. correct !
  45. ; ReTested with 895*895+1: ok,gives 895
  46. ; ReTested with 895*895: ok,gives 895
  47. ; Tested with 896*896: ok,gives 896, BUT DOES THE low CYCLE! 896 is in the table! must do directly!
  48. ; ReTested with 896*896: ok,does directly.
  49.  
  50. Table:    incbin    "ram:pytree.table"
  51.